import React from 'react'
import { useForm } from '.';
import FieldContext from './FieldContext';

export default function Form(props) {
  const { children, form, onFinish, onFinishFailed } = props;
  const [formInstance] = useForm(form);
  formInstance.setCallback({
    onFinish,
    onFinishFailed
  });
  return (
    <form
      onSubmit={e => {
        e.preventDefault();
        // console.log('提交')
        formInstance.submit();
      }}>
      <FieldContext.Provider value={formInstance}>
        {children}
      </FieldContext.Provider>
    </form>
  )
}
